package com.buyouchina.bean.product;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.buyouchina.bean.area.Province;

/**
 * 核算
 * */
@Entity
@Table(name = "account")
public class Account {

	@Id
	@GeneratedValue
	private Integer id;

	// 数量
	private Double quantity;
	
	// 操作类型(买入&卖出)
	@Enumerated(EnumType.STRING)
	@Column(length = 20)
	private DateType dateType;
	
	// 操作类型(买入&卖出)
	@Enumerated(EnumType.STRING)
	@Column(length = 20)
	private AccountType type;

	// 核算级别(市级别&县级别)
	@Enumerated(EnumType.STRING)
	@Column(length = 20)
	private AccountAreaType areaType;

	// 时间
	@Temporal(TemporalType.DATE)
	private Date date;

	// 货物
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "product_id")
	private Product product;

	// 统计记录的区域
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "province_id")
	private Province province;
	
	// 店铺里的人员
	@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinTable(name = "account_tongji", 
			joinColumns = { @JoinColumn(name = "account_id", referencedColumnName = "id", nullable = true) }, 
			inverseJoinColumns = { @JoinColumn(name = "tongji_id", referencedColumnName = "id", nullable = true) })
	private Set<Statistical> tongjis = new HashSet<Statistical>();

	public enum AccountType {
		SALES {
			public String getName() {
				return "销售统计";
			}
		},
		PURCHASE {
			public String getName() {
				return "进货统计";
			}
		};
		public abstract String getName();
	}

	public enum AccountAreaType {
		CITYLEVEL {
			public String getName() {
				return "市级";
			}
		},
		COUNTYLEVEL {
			public String getName() {
				return "省级";
			}
		},
		STATELEVEL {
			public String getName() {
				return "国家级";
			}
		};
		public abstract String getName();
	}
	
	public enum DateType {
		DAY {
			public String getName() {
				return "市级";
			}
		},
		WEEK {
			public String getName() {
				return "省级";
			}
		},
		MONTH {
			public String getName() {
				return "国家级";
			}
		},
		YEAR {
			public String getName() {
				return "省级";
			}
		};
		public abstract String getName();
	}


	public Account() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Province getProvince() {
		return province;
	}

	public void setProvince(Province province) {
		this.province = province;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Double getQuantity() {
		return quantity;
	}

	public void setQuantity(Double quantity) {
		this.quantity = quantity;
	}

	public AccountType getType() {
		return type;
	}

	public void setType(AccountType type) {
		this.type = type;
	}

	public AccountAreaType getAreaType() {
		return areaType;
	}

	public void setAreaType(AccountAreaType areaType) {
		this.areaType = areaType;
	}

	public Set<Statistical> getTongjis() {
		return tongjis;
	}

	public void setTongjis(Set<Statistical> tongjis) {
		this.tongjis = tongjis;
	}

	public DateType getDateType() {
		return dateType;
	}

	public void setDateType(DateType dateType) {
		this.dateType = dateType;
	}

}
